#include "trayicon.h"

BOOL CreateTrayIcon(HWND hWnd)
{
	ZeroMemory(&_iconData, sizeof(NOTIFYICONDATA));

	_iconData.cbSize = sizeof(NOTIFYICONDATA);
	_iconData.hWnd = hWnd;
	_iconData.uID = 0;
	_iconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
	_iconData.uCallbackMessage = WM_SYSICON;
	_iconData.hIcon = (HICON)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
	wcsncpy_s(_iconData.szTip, TRAYICON_TOOLTIP, sizeof(TRAYICON_TOOLTIP));

	return Shell_NotifyIcon(NIM_ADD, &_iconData);
}

BOOL DestroyTrayIcon()
{
	return Shell_NotifyIcon(NIM_DELETE, &_iconData);
}

BOOL SetTrayIconToolTip(WCHAR* text)
{
	NOTIFYICONDATA iconData1;
	memcpy(&iconData1, &_iconData, sizeof(_iconData));

	wcsncpy_s(iconData1.szTip, text, sizeof(TRAYICON_TOOLTIP));
	return Shell_NotifyIcon(NIM_MODIFY, &iconData1);
}

BOOL SetTrayIconIcon(DWORD IconID)
{
	NOTIFYICONDATA iconData1;
	memcpy(&iconData1, &_iconData, sizeof(_iconData));
	iconData1.hIcon = (HICON)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IconID));

	return Shell_NotifyIcon(NIM_MODIFY, &iconData1);
}